package com.ruoyi.web.controller.api;

import com.ruoyi.common.annotation.CheckSwitch;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BasicsController;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.ResponsePageInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.cs.domain.TWar;
import com.ruoyi.cs.domain.apiVo.TWarDto;
import com.ruoyi.cs.service.ITWarService;
import com.ruoyi.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 战令Controller
 * 
 * @author ruoyi
 * @date 2023-12-11
 */
@Api(tags = {"战令模块webApi接口"})
@RestController
@RequestMapping("/cs/warapi")
public class TWarApiController extends BasicsController
{
    @Autowired
    private ITWarService tWarService;
    @Autowired
    private TokenService tokenService;

    /**
     * @Desc: 显示战令系统
     * @author: zz
     * @date: 2023/12/12
     */
    @ApiOperation("战令信息接口")
    @GetMapping("/common/show")
    public Response<TWarDto> show()
    {
        String userId = null;
        LoginUser loginUser = tokenService.getLoginUserWeb(ServletUtils.getRequest());
        if(loginUser != null){
            userId = loginUser.getUser().getLoginUserId();
        }
        try {
            return Response.success(tWarService.getInfo(userId));
        } catch (Exception e) {
            return Response.fail("系统繁忙");
        }
    }

    @CheckSwitch
    @ApiOperation("单个战令奖励领取")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warId",value = "战令ID" ,dataType = "string", paramType = "path", required = true),
            @ApiImplicitParam(name = "grate",value = "战令等级" ,dataType = "Integer", paramType = "path", required = true)
    })
    @PutMapping("/{warId}/receive/{grate}")
    public Response singleReceive(@PathVariable("warId") String warId,@PathVariable("grate") Integer grate){
        String userId = tokenService.getLoginUserId();
        try {
            return tWarService.singleReceive(warId,grate,userId);
        } catch (Exception e) {
            logger.error("单个战令奖励领取异常:{}",e);
            return Response.fail("系统繁忙，请稍后重试！");
        }
    }

    @CheckSwitch
    @ApiOperation("一键领取战令奖励")
    @PutMapping("/{warId}/receive/all")
    @ApiImplicitParam(name = "warId",value = "战令ID" ,dataType = "string", paramType = "path", required = true)
    public Response singleReceive(@PathVariable("warId") String warId){
        String userId = tokenService.getLoginUserId();
        try {
            return tWarService.receive(warId,userId);
        } catch (Exception e) {
            logger.error("一键领取战令奖励异常:{}",e);
            return Response.fail("系统繁忙，请稍后重试！");
        }
    }

}
